<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-09-29
 * Time: 13:48
 */

namespace backend\controllers;
use app\models\AuthItemChild;
use app\models\CrmFrontPermission;
use app\models\CrmSystemGsxx;
use app\models\Mylogs;
use app\models\search\MylogsSearch;
use common\helps\Tools;
use mdm\admin\components\Configs;
use mdm\admin\components\Helper;
use mdm\admin\models\AuthItem;
use mdm\admin\models\Route;
use mdm\admin\models\searchs\AuthItem as AuthItemSearch;
use yii\base\Object;
use yii\helpers\ArrayHelper;
use yii\rbac\Item;

class LogsController extends CommonController
{

//    /**
//     * 写日志
//     * @return string
//     * @throws \Throwable
//     * @throws \yii\db\StaleObjectException
//     */
//    public function actionWrite()
//    {
//        Tools::writeToLogPlus("./logs/".\Yii::$app->user->id.'/',$_POST['myLogs']);
//        return $this->dealFD('写日志成功！',1);
//    }
//    public function actionList()
//    {
//        $files = Tools::scanFilePlus("./logs/".\Yii::$app->user->id.'/',$_POST['limit'],$_POST['page'],$total);
//        return $this->actionLayData($total,$files);
//    }
//    public function actionView()
//    {
//        $files = Tools::scanOneFilePlus("./logs/".\Yii::$app->user->id.'/',$_POST['name']);
//        return $this->dealFD(json_decode($files,true),1);
//    }

    /**
     * 写日志
     * @return string
     * @throws \Throwable
     * @throws \yii\db\StaleObjectException
     */
    public function actionWrite()
    {
        $myLogs = new Mylogs();
        if($myLogs->load($_POST['data'])&&$myLogs->save()){
            return $this->dealFD('写日志成功！',1);
        }else{
            return $this->dealFD('写日志失败！',0);
        };
    }
    public function actionList()
    {
        $myLogs = new MylogsSearch();
        $res = $myLogs->search(\Yii::$app->request->post());
        $count = $res->query->count();
        $res->query->limit($_POST['limit']);
        $res->query->offset($_POST['limit']*($_POST['page']-1));
        $resArr = $res->query->asArray()->all();
        return $this->actionLayData($count,$resArr);
    }

}